//
// Created by v on 19-4-29.
//

#ifndef CUTEDEVICE_CMFIFOHANDLER_H
#define CUTEDEVICE_CMFIFOHANDLER_H

#include "cm_fifo.h"
#include "iostream"
#include <mutex>

#define LOGFIFO(fmt, ...)                                                      \
    do                                                                         \
    {                                                                          \
        printf("%s:%d ", __func__, __LINE__);                                  \
        printf(fmt, ##__VA_ARGS__);                                            \
    } while (0)

static std::mutex m_mutex;

class CMFifoHandler
{
  public:
    static CMFifoHandler *getInstance()
    {
        m_mutex.lock();
        static CMFifoHandler m_fifoHandler;
        m_mutex.unlock();
        return &m_fifoHandler;
    }

    int open(std::string path);
    int close();

    int write(std::string cmd, std::string data);

  private:
    CMFifoHandler(){};
    CMFifoWriteHandle writeHandle;
};

#endif // CUTEDEVICE_CMFIFOHANDLER_H
